package sicnu.cs.aps.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import sicnu.cs.aps.domain.entity.TeamMember;
import sicnu.cs.aps.mapper.TeamMemberMapper;
import sicnu.cs.aps.service.ITeamMemberService;

import java.util.List;

/**
 * @author chengke
 * @version 1.0
 * @className TeamMemberServiceImpl
 * @description 队长邀请成员实现类
 * @date 2022/5/29 15:08
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class TeamMemberServiceImpl extends ServiceImpl<TeamMemberMapper, TeamMember> implements ITeamMemberService {

    private final TeamMemberMapper teamMemberMapper;

    @Override
    public Integer isInTeam(Long teamMemberId, Long activityId) {
        return teamMemberMapper.isInvited(teamMemberId, activityId);
    }

    /**
     * 判断成员是否在小队内
     *
     * @param userId 用户id
     * @param teamId 队伍id
     * @return true 在小队内 false 不在小队内
     */
    @Override
    public boolean isMemberInTeam(Long userId, Long teamId) {
        List<TeamMember> teamMembers = teamMemberMapper.listUserInTeam(teamId);
        return teamMembers.stream().anyMatch(teamMember -> teamMember.getUserId().equals(userId));
    }
}